package com.airycode.distribution.distribution1.controller;

/**
 * 公司自定义Controller
 * Created by zkr-fanxirui on 2017/8/19.
 */

import com.airycode.distribution.distribution1.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    //公司信息列表
    @RequestMapping("/companyList")
    public String companyList(HttpServletRequest request, HttpServletResponse response){
        String resultPage = "";
        Map<String,Object> resultMap = new HashMap<String,Object>();
        Map<String,Object> dataMap = new HashMap<String,Object>();
        dataMap = companyService.getCompanys();
        resultMap.put("dataMap",dataMap);
        resultPage="company/company-list";
        request.setAttribute("resultMap",resultMap);
        return resultPage;
    }

    //自定义表单页面
    @RequestMapping("/goToCustormFormPage")
    public String goToCustormFormPage(HttpServletRequest request, HttpServletResponse response){
        String resultPage = "/form_builder";
        Map<String,Object> resultMap = new HashMap<String,Object>();
        Map<String,Object> dataMap = new HashMap<String,Object>();
        String id = request.getParameter("id");
        dataMap.put("id",id);
        resultMap.put("dataMap",dataMap);
        request.setAttribute("resultMap",resultMap);
        return resultPage;
    }


    @RequestMapping("/saveHtmlCode")
    public void saveHtmlCode(HttpServletRequest request, HttpServletResponse response){

        Map<String,Object> resultMap = new HashMap<String,Object>();
        Map<String,Object> dataMap = new HashMap<String,Object>();
        String id = request.getParameter("htmlCode");

        dataMap.put("id",id);
        resultMap.put("dataMap",dataMap);
        request.setAttribute("resultMap",resultMap);

    }

    //保存查看

    @RequestMapping("/saveHtmlCodeAndLook")
    public String saveHtmlCodeAndLook(HttpServletRequest request, HttpServletResponse response){

        String resultPage = "autoForm/form_look";
        Map<String,Object> resultMap = new HashMap<String,Object>();
        Map<String,Object> dataMap = new HashMap<String,Object>();
        String id = request.getParameter("id");

        dataMap.put("id",id);
        resultMap.put("dataMap",dataMap);
        request.setAttribute("resultMap",resultMap);
        return resultPage;

    }


}
